package com.renshine.business.server.service.${module}.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.renshine.business.repository.dao.${module}.${Entity}Dao;
import com.renshine.business.repository.entity.${module}.${Entity};
import com.renshine.business.repository.util.PagerUtil;
import com.renshine.business.server.service.${module}.${Entity}Service;

@Service
public class ${Entity}ServiceImpl implements ${Entity}Service {

	@Autowired
	${Entity}Dao ${entity}Dao;
	
	@Override
	public Map<String, Object> search(Map<String, String> params, int pageIndex, int limit) {
		List<${Entity}> list = null;
		int total = ${entity}Dao.count(params);
		if (total > 0) {
			list = ${entity}Dao.search(params, PagerUtil.pageBounds(pageIndex, limit));
		}
		return PagerUtil.backMapData(total, list);
	}

	@Override
	@Transactional
	public void save(${Entity} ${entity}) {
		Assert.notNull(${entity});
		${entity}Dao.insert(${entity});
	}

	@Override
	@Transactional
	public void modify(${Entity} ${entity}) {
		Assert.notNull(${entity});
		${entity}Dao.update(${entity});
	}

	@Override
	@Transactional
	public void remove(String ${tb.pk.javaName}) {
		Assert.notNull(${tb.pk.javaName});
		${entity}Dao.delete(${tb.pk.javaName});
	}

	@Override
	public ${Entity} detail(${tb.pk.javaType} ${tb.pk.javaName}) {
		Assert.notNull(${tb.pk.javaName});
		return ${entity}Dao.select(${tb.pk.javaName});
	}

}
